// 电话号码的字母组合
var dfs = function (result, map, string, index, temp) {
  if (index === string.length) {
    result.push(temp)
  } else {
    let char = string[index]
    let letters = map.get(char)
    for (let letter of letters) {
      dfs(result, map, string, index + 1, temp + letter)
    }
  }
}
var letterCombinations = function (digits) {
  let combinations = []
  if (digits.length === 0) return combinations
  let phoneMap = new Map([
    ['2', 'abc'],
    ['3', 'def'],
    ['4', 'ghi'],
    ['5', 'jkl'],
    ['6', 'mno'],
    ['7', 'pqrs'],
    ['8', 'tuv'],
    ['9', 'wxyz'],
  ])

  dfs(combinations, phoneMap, digits, 0, '')
  return combinations
}

let r = letterCombinations('23')
console.log(r)
